<?php
class AdBlock extends BlockInstance {
	public $CI;
	
	function AdBlock()
	{
		$this->CI =& get_instance();
	}
	
	function __call($m, $a)
	{
		global $BBX;
		
		// grab internal ad flag
		$query 	 = $this->CI->db->query('select use_internal_ads from bricaboxes where id = ?', array($BBX['bricabox']->id));
		$use_int = $query->first_row()->use_internal_ads;
		
		$code 	  = $this->get_setting($a[0]['data'], 'ad_code');
		if (strpos($m, 'large') !== false)
		{
			$gad_code = <<<AD
				<script type="text/javascript"><!--
				google_ad_client = "pub-8744404232519222";
				/* 468x60, created 2/20/08 */
				google_ad_slot = "3172849756";
				google_ad_width = 468;
				google_ad_height = 60;
				//-->
				</script>
				<script type="text/javascript"
				src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
				</script>
AD;
		}
		elseif (strpos($m, 'small') !== false)
		{
			$gad_code = <<<AD
				<script type="text/javascript"><!--
				google_ad_client = "pub-8744404232519222";
				/* 250x250, created 2/20/08 */
				google_ad_slot = "7329963242";
				google_ad_width = 250;
				google_ad_height = 250;
				//-->
				</script>
				<script type="text/javascript"
				src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
				</script>
AD;
		}
		
		/**
		 * Subdomains of bricaboxes that get 100% of ad calls
		 */
		$all_calls = array(
			'xrobotcoop',
			'mashbase',
			'whostech'
		);
		
		if (!in_array($BBX['bricabox']->subdomain, $all_calls) && $use_int)
			$data['ad_code'] = $gad_code;
		else
		{
			// custom ad code
			$data['ad_code'] = strlen($code) ? $code : $gad_code;
		}
		$data['inst']  = $a[0]['data'];
		$data['value'] = $code;
		$this->CI->load->view('blocks/ad_block/block', $data);
	}
}
?>